package com.yanqu.road.server.pb;

import com.yanqu.road.entity.minewar.*;
import com.yanqu.road.entity.player.UserMineWarPatronsData;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.minewar.MineWarProto;
import com.yanqu.road.pb.player.PlayerProto;

import java.util.List;


public class MineWarPb {

	public static MineWarProto.MineStationTempMsg.Builder parseMineStationTempMsg(MineStationInfo mineStationInfo) {
		if(null == mineStationInfo){
			return null;
		}
		MineWarProto.MineStationTempMsg.Builder msg = MineWarProto.MineStationTempMsg.newBuilder();
		msg.setMineType(mineStationInfo.getMineType());
		msg.setStationId(mineStationInfo.getStationId());
		msg.setOccupyCount(mineStationInfo.getOccupyCount());
		msg.setAverageAbility(mineStationInfo.getAverageAbility().toString());
		return msg;
	}

	public static MineWarProto.MinePitTempMsg.Builder parseMinePitTempMsg(UserMinePit userMinePit) {
		if(null == userMinePit){
			return null;
		}
		MineWarProto.MinePitTempMsg.Builder msg = MineWarProto.MinePitTempMsg.newBuilder();
		msg.setMineType(userMinePit.getMineType());
		msg.setPitId(userMinePit.getPitId());
		msg.setStationId(userMinePit.getStationId());
		msg.setUserId(userMinePit.getUserId());
		msg.setNickName(userMinePit.getNickName());
		msg.setDecoration(userMinePit.getDecoration());
		msg.setTitleId(1);
		msg.setCity("");
		msg.setUnionName(userMinePit.getUnionName());
		return msg;
	}

	public static MineWarProto.MyMinePitTempMsg.Builder parseMyMinePitTempMsg(UserMinePit userMinePit, boolean isRemove) {
		if(null == userMinePit){
			return null;
		}
		MineWarProto.MyMinePitTempMsg.Builder msg = MineWarProto.MyMinePitTempMsg.newBuilder();
		msg.setMineType(userMinePit.getMineType());
		msg.setPitId(userMinePit.getPitId());
		msg.setIsRemove(isRemove);
		if(!isRemove){
			msg.setLastGetRewardTime(userMinePit.getLastGetRewardTime());
			if (null != userMinePit.getPatronsIdList()) {
				msg.addAllPatronsIdList(userMinePit.getPatronsIdList());
			}
		}
		return msg;
	}

	public static MineWarProto.MineWarRecordTempMsg.Builder parseMineWarRecordTempMsg(MineWarRecord mineWarRecord) {
		if(null == mineWarRecord){
			return null;
		}
		MineWarProto.MineWarRecordTempMsg.Builder msg = MineWarProto.MineWarRecordTempMsg.newBuilder();
		msg.setRecordUid(mineWarRecord.getRecordUid());
		msg.setMineType(mineWarRecord.getMineType());
		msg.setPitId(mineWarRecord.getPitId());
		msg.setEnemyUserId(mineWarRecord.getEnemyUserId());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(mineWarRecord.getEnemyBaseData());
		msg.setEnemyBaseData(baseMsg);
		msg.setRecordTime(mineWarRecord.getRecordTime());
		msg.setIsWin(mineWarRecord.isWin());
		return msg;
	}

	public static MineWarProto.MineWarNoticeTempMsg.Builder parseMineWarNoticeTempMsg(MineWarNotice mineWarNotice) {
		if(null == mineWarNotice){
			return null;
		}
		MineWarProto.MineWarNoticeTempMsg.Builder msg = MineWarProto.MineWarNoticeTempMsg.newBuilder();
		msg.setNoticeUid(mineWarNotice.getNoticeUid());
		msg.setMineType(mineWarNotice.getMineType());
		msg.setPitId(mineWarNotice.getPitId());
		msg.setNoticeTime(mineWarNotice.getNoticeTime());
		msg.setUserId(mineWarNotice.getUserId());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(mineWarNotice.getUserBaseInfo());
		msg.setPlayerBaseData(baseMsg);
		msg.setEnemyUserId(mineWarNotice.getEnemyUserId());
		baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(mineWarNotice.getEnemyBaseInfo());
		msg.setEnemyBaseData(baseMsg);
		return msg;
	}

	public static MineWarProto.MineRefugeTempMsg.Builder parseMineRefugeTempMsg(UserMineRefuge userMineRefuge) {
		if(null == userMineRefuge){
			return null;
		}
		MineWarProto.MineRefugeTempMsg.Builder msg = MineWarProto.MineRefugeTempMsg.newBuilder();
		msg.setMineType(userMineRefuge.getMineType());
		msg.setPitId(userMineRefuge.getPitId());
		msg.setLastGetRewardTime(userMineRefuge.getLastGetRewardTime());
		if(null != userMineRefuge.getPatronsIdList()) {
			msg.addAllPatronsIdList(userMineRefuge.getPatronsIdList());
		}
		return msg;
	}

	public static MineWarProto.MineStationListMsg.Builder parseMineStationListMsg(List<MineStationInfo> mineStationInfoList){
		MineWarProto.MineStationListMsg.Builder listMsg = MineWarProto.MineStationListMsg.newBuilder();
		if(null != mineStationInfoList){
			for(MineStationInfo mineStationInfo : mineStationInfoList){
				MineWarProto.MineStationTempMsg.Builder msg = parseMineStationTempMsg(mineStationInfo);
				if(null != msg){
					listMsg.addMineStationList(msg);
				}
			}
		}
		return listMsg;
	}

	public static MineWarProto.MinePitListMsg.Builder parseMinePitListMsg(List<UserMinePit> userMinePitList){
		MineWarProto.MinePitListMsg.Builder listMsg = MineWarProto.MinePitListMsg.newBuilder();
		if(null != userMinePitList){
			for(UserMinePit userMinePit : userMinePitList){
				MineWarProto.MinePitTempMsg.Builder msg = parseMinePitTempMsg(userMinePit);
				if(null != msg){
					listMsg.addMinePitList(msg);
				}
			}
		}
		return listMsg;
	}

	public static MineWarProto.MyMinePitListMsg.Builder parseMyMinePitListMsg(List<UserMinePit> userMinePitList, boolean isRemove){
		MineWarProto.MyMinePitListMsg.Builder listMsg = MineWarProto.MyMinePitListMsg.newBuilder();
		if(null != userMinePitList){
			for(UserMinePit userMinePit : userMinePitList){
				MineWarProto.MyMinePitTempMsg.Builder msg = parseMyMinePitTempMsg(userMinePit, isRemove);
				if(null != msg){
					listMsg.addMinePitList(msg);
				}
			}
		}
		return listMsg;
	}

	public static MineWarProto.MineWarRecordListMsg.Builder parseMineWarRecordListMsg(List<MineWarRecord> mineWarRecordList){
		MineWarProto.MineWarRecordListMsg.Builder listMsg = MineWarProto.MineWarRecordListMsg.newBuilder();
		if(null != mineWarRecordList){
			for(MineWarRecord mineWarRecord : mineWarRecordList){
				MineWarProto.MineWarRecordTempMsg.Builder msg = parseMineWarRecordTempMsg(mineWarRecord);
				if(null != msg){
					listMsg.addMineWarRecordList(msg);
				}
			}
		}
		return listMsg;
	}

	public static MineWarProto.MineWarNoticeListMsg.Builder parseMineWarNoticeListMsg(List<MineWarNotice> mineWarNoticeList){
		MineWarProto.MineWarNoticeListMsg.Builder listMsg = MineWarProto.MineWarNoticeListMsg.newBuilder();
		if(null != mineWarNoticeList){
			for(MineWarNotice mineWarNotice : mineWarNoticeList){
				MineWarProto.MineWarNoticeTempMsg.Builder msg = parseMineWarNoticeTempMsg(mineWarNotice);
				if(null != msg){
					listMsg.addMineWarNoticeList(msg);
				}
			}
		}
		return listMsg;
	}

	public static MineWarProto.MineRefugeListMsg.Builder parseMineRefugeListMsg(List<UserMineRefuge> userMineRefugeList){
		MineWarProto.MineRefugeListMsg.Builder listMsg = MineWarProto.MineRefugeListMsg.newBuilder();
		if(null != userMineRefugeList){
			for(UserMineRefuge userMineRefuge : userMineRefugeList){
				MineWarProto.MineRefugeTempMsg.Builder msg = parseMineRefugeTempMsg(userMineRefuge);
				if(null != msg){
					listMsg.addMineRefugeList(msg);
				}
			}
		}
		return listMsg;
	}

	public static MineWarProto.MineWarPatronsDataTempMsg.Builder parseMineWarPatronsDataTempMsg(UserMineWarPatronsData userMineWarPatronsData){
		if(null == userMineWarPatronsData){
			return null;
		}
		MineWarProto.MineWarPatronsDataTempMsg.Builder msg = MineWarProto.MineWarPatronsDataTempMsg.newBuilder();
		msg.setPatronsId(userMineWarPatronsData.getPatronsId());
		msg.setBattleTimes(userMineWarPatronsData.getBattleTimes());
		msg.setBuyBattleTimes(userMineWarPatronsData.getBuyBattleTimes());
		msg.setIsDispatchMine(userMineWarPatronsData.getDispatchMine() > 0);
		return msg;
	}

	public static MineWarProto.MineWarPatronsDataListMsg.Builder parseMineWarPatronsDataListMsg(List<UserMineWarPatronsData> userMineWarPatronsDataList){
		MineWarProto.MineWarPatronsDataListMsg.Builder listMsg = MineWarProto.MineWarPatronsDataListMsg.newBuilder();
		if(null != userMineWarPatronsDataList){
			for(UserMineWarPatronsData userMineWarPatronsData : userMineWarPatronsDataList){
				MineWarProto.MineWarPatronsDataTempMsg.Builder msg = parseMineWarPatronsDataTempMsg(userMineWarPatronsData);
				if(null != msg){
					listMsg.addPatronsDataList(msg);
				}
			}
		}
		return listMsg;
	}
}
